package cn.servlet;

import cn.entity.Goods;
import cn.entity.Kind;
import cn.service.GoodsService;
import cn.service.KindService;
import cn.service.impl.GoodsServiceImpl;
import cn.service.impl.KindServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/goods")
public class GoodsServlet extends HttpServlet {
	KindService kindService=new KindServiceImpl();
	GoodsService goodsService=new GoodsServiceImpl();
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GoodsServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action=request.getParameter("action");
		switch(action){
		case "query":
			query(request,response);
			break;
		case "detail":
			detail(request,response);
			break;
		}
	}
	//查询
	protected void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}
	
	
	protected void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id=request.getParameter("id");
		Goods goods=goodsService.selectByPrimaryKey(id);
		Kind kind=kindService.selectByPrimaryKey(goods.getKid());
		goods.setKind(kind);
		request.setAttribute("goods", goods);
		//查询所有该商品的评价
		
		request.getRequestDispatcher("detail.jsp").forward(request, response);
	}
	
	

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}
